package com.example.musicrecommend.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.musicrecommend.common.ErrorCode;
import com.example.musicrecommend.exception.ThrowUtils;
import com.example.musicrecommend.mapper.CollectMapper;
import com.example.musicrecommend.model.entity.Collect;
import com.example.musicrecommend.model.vo.SongVO;
import com.example.musicrecommend.service.CollectService;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
* @author PERSON
* @description 针对表【collect(收藏)】的数据库操作Service实现
* @createDate 2024-10-03 17:12:22
*/
@Service
public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect>
    implements CollectService{

    @Override
    public void validCollect(Collect collect,boolean hasId) {
        ThrowUtils.throwIf(collect == null, ErrorCode.PARAMS_ERROR);
        Long id = collect.getId();
        Long userId = collect.getUserId();
        Long songId = collect.getSongId();

        if(hasId) {
            ThrowUtils.throwIf(id<=0,ErrorCode.PARAMS_ERROR);
        }
        ThrowUtils.throwIf(userId <=0 || songId<=0,ErrorCode.PARAMS_ERROR);
    }

    @Override
    public Page<SongVO> selectCollectSongsPage(Page<SongVO> page, Long userId) {
        return this.getBaseMapper().selectCollectSongsPage(page,userId);
    }

    @Override
    public Collect selectOneIncludeDeleted(Wrapper<Collect> queryWrapper) {
        return  this.getBaseMapper().selectOneIncludeDeleted(queryWrapper);
    }

    @Override
    public Boolean updateCollectById(Serializable id, Collect newCollect) {
        return this.getBaseMapper().updateCollectById(id,newCollect);
    }
}




